package com.ruoyi.web.core.config;

import com.ruoyi.by.health.domain.entity.ByhealthEmployee;
import com.ruoyi.by.health.domain.form.EmployeeGameForm;
import com.ruoyi.by.health.domain.vo.EmployeeGameVo;
import com.ruoyi.by.health.service.IByhealthEmployeeService;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

@Component
public class GameScoreInitConfig {
    @Autowired
    IByhealthEmployeeService employeeService;
    @Resource
    RedisTemplate<String, Object> redisTemplate;
    private static final Logger log = LoggerFactory.getLogger(GameScoreInitConfig.class);
    //所有城市
/*    private static List<PubListVo> allCity = new ArrayList<>();
    private static List<SysCityDO> allCityList = new ArrayList<>();*/

    /**
     * 初始化省市县
     */
    @PostConstruct
    public void initGameScoreRegion() {

        log.info("----开始初始化员工游戏排名到redis-----");
        EmployeeGameForm  gameScoreQo = new EmployeeGameForm();

        List<EmployeeGameVo> gameScoreList = employeeService.gameScoreList(gameScoreQo);
        ZSetOperations<String, Object> zSetOperations = redisTemplate.opsForZSet();
        if (!CollectionUtils.isEmpty(gameScoreList)) {
            //zSetOperations.remove("emp_game_score", "上海");
            redisTemplate.delete("emp_game_score");
            for (EmployeeGameVo gameScore : gameScoreList) {
                zSetOperations.add("emp_game_score", gameScore.getEmpId(), gameScore.getGameScore());
            }
        }
        log.info("----初始化员工游戏排名到redis完成-----");
    }

}
